package com.example.rule.controller;


import com.example.rule.common.result.Result;
import com.example.rule.common.web.Results;
import com.example.rule.entity.dto.RuleSaveDTO;
import com.example.rule.service.RuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rule")
@RequiredArgsConstructor
@Tag(name = "规则管理", description = "用于管理规则")
public class RuleController {

    private final RuleService ruleService;

    @PostMapping("/save")
    @Operation(summary = "新增规则", description = "根据传入参数保存一个新的规则")
    @ApiResponse(responseCode = "200", description = "操作成功", content = @Content(mediaType = "application/json"))
    public Result<Void> save(@RequestBody @Schema(description = "规则保存请求参数") RuleSaveDTO params) {
        ruleService.save(params);
        return Results.success();
    }


    @PostMapping("/execute")
    @Operation(summary = "执行规则", description = "执行所有规则")
    @ApiResponse(responseCode = "200", description = "操作成功", content = @Content(mediaType = "application/json"))
    public Result<Void> execute() {
        ruleService.execute();
        return Results.success();
    }


}
